﻿using System;
using System.Collections.Generic;
using System.Linq;
using Gp.Scripts.Data.Skills;
using Gp.Scripts.Equip;
using Gp.Scripts.Core;
using Sirenix.OdinInspector;


namespace Gp.Scripts.Data {
    [Serializable]
    public abstract class RangedBaseWeaponType : BaseWeaponType {
        [LabelText("单发伤害")] public int damage;

        [LabelText("射速")] [MinValue(1)] public int shootSpeed = 1;
        [ShowIf("@shootSpeed > 1")] [LabelText("间断射击")] [ToggleLeft] public bool discontinuous = true;

        [LabelText("弹匣容量")] public int capacity;


        [LabelText("压制点")]
        [HorizontalGroup("SP")]
        public int suppressPoint;
        


        // public override StatField RequireStat => StatField.None;

        public override WeaponBasicType WeaponBasicType => WeaponBasicType.Ranged;


        /// <summary>
        /// 远程武器可攻击所有目标
        /// </summary>
        /// <param name="unitAbilityData"></param>
        /// <returns></returns>
        // public override List<AttachCell> GetTargets(UnitAbilityContext unitAbilityData) {
        //     var placeHolder = CellGridSystem.Instance.PlaceHolder;
        //     
        //     // 如果有护盾单位，则只能攻击护盾单位
        //     // var shieldUnits = unitAbilityData.Targets
        //     //     .Where(x => placeHolder.GetUnit(x) is { } u && u.EquipHolder.GetShieldArmorPoints() > 0)
        //     //     .ToList();
        //     var res = new List<AttachCell>(4);
        //
        //     foreach (var cell in unitAbilityData.Targets) {
        //         if (placeHolder.GetUnit(cell) is not {} u) continue;
        //         res.Add(cell);
        //         if (u.EquipHolder.HasShield()) break;
        //     }
        //     
        //     
        //     return res;
        // }
        
        public virtual CostInfo Cost => CostInfo.All;


        public bool Discontinuous => discontinuous && shootSpeed > 1; 
        


        public override WeaponTypeInfo BuildInfo(WeaponEntity entity) {
            return new RangedWeaponInfo(this, entity);
        }

// #if UNITY_EDITOR
//         private void UpdateSp() {
//             fullSp = Math.Max(fullSp, suppressPoint);
//         }
// #endif
    }
}